package com.kingmed.kmss.gateway.config.sa;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;

import com.kingmed.kmss.common.dto.admin.ums.AdminAuthDTO;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限验证接口扩展
 */
@Component
public class StpInterfaceImpl implements StpInterface {


    public static final String LOGIN_USER_KEY = "loginUser";

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 返回此 loginId（当前登录者）拥有的权限码列表
        AdminAuthDTO adminAuthDto = (AdminAuthDTO) StpUtil.getSession().get(LOGIN_USER_KEY);
        return adminAuthDto.getResourceList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 返回此 loginId（当前登录者）拥有的角色码列表
        AdminAuthDTO adminAuthDto = (AdminAuthDTO) StpUtil.getSession().get(LOGIN_USER_KEY);
        return adminAuthDto.getRoleList();
    }

}

